<template>
    <div class="agency">
        <div v-show="userType !== 'ADMIN'" class="errText">您有 <span class="eventLength">{{ total }}</span> 条代办事项
        </div>
        <div v-show="userType == 'ADMIN'" class="errText">有 <span class="eventLength">{{ total }}</span> 条代办事项进行中
        </div>
        <el-table border ref="singleTable" :data="tableData" style="width: 100%" height="310">
            <el-table-column type="index" label="序号" width="50">
            </el-table-column>
            <el-table-column label="作业类型">
                <template slot-scope="scope">
                    {{ workType[scope.row.workType] }}
                </template>
            </el-table-column>
            <el-table-column prop="facilityName" label="作业设施">
            </el-table-column>
            <el-table-column prop="batchName" label="作业批次">
            </el-table-column>
            <el-table-column prop="staffName" label="作业人">
            </el-table-column>
            <el-table-column label="作业时间" width="260">
                <template slot-scope="scope">
                    {{ scope.row.workStartTime + '至' + scope.row.workEndTime }}
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button @click="handleClick(scope.row)" type="text" size="small">去处理</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="paginationModule">
            <Pagination @size-Change="handleSizeChange" :size="size" @current-change="handleCurrentChange" :page="page"
                :total="total">
            </Pagination>
        </div>
    </div>
</template>
<script>
import jobTaskManagement from '@/api/jobManagment/jobTaskManagement';
import Pagination from '@/components/Pagination';
export default {
    components: { Pagination },
    data() {
        return {
            tableData: [],
            page: 1,
            size: 6,
            total: 10,
            workStatus: {
                COMPLETE: "按时完成",
                LATE_COMPLETE: "逾期完成",
                LATE_PENDING_PROCESS: "逾期待处理",
                PENDING_PROCESS: "待处理",
                VOIDED: "已作废"
            },
            workType: {
                CHANGE_WATER: "换水作业",
                HANGING_NET: "吊网作业",
                EXPOSED_NET: "漏网作业",
                FEEDING: "饲喂作业",
                DISINFECTION_WATER: '消杀作业',
            },
            eventLength: 0,
            userType: '',
            staffName: '',
            personNo: ''
        }
    },
    watch: {},
    computed: {
        person() {
            return this.$store.state.initData.person || [];
        }
    },
    mounted() {
        this.queryPageByCondition();
    },
    methods: {
        queryPageByCondition() {
            let logInfo = sessionStorage.logInfo ? JSON.parse(sessionStorage.logInfo) : {};
            this.userType = logInfo.userType || '';
            let params = {
                page: this.page,
                size: this.size,
                entity: {
                    workStatus: 'PENDING_PROCESS'
                }
            }
            if (this.userType == 'ADMIN') {
                params.entity.staffName = ''
            } else {
                let personNo = logInfo.personNo || '';
                let rut = this.person.find(item => {
                    return item.person.personNo == personNo
                })
                if (rut) {
                    this.staffName = rut.person.name || ''
                } else {
                    this.staffName = ''
                }
                params.entity.staffName = this.staffName
            }
            jobTaskManagement.queryPageByCondition(params).then(res => {
                if (res.code == 1) {
                    this.tableData = res.data.content || [];
                    this.total = res.data.totalElements;
                } else {
                    this.$message.warning(res.msg || '分页查询失败')
                }
                this.queryByCondition()
            }).catch(err => {
                console.log(err)
            })
        },
        queryByCondition() {
            jobTaskManagement.queryByCondition({
                workStatus: 'PENDING_PROCESS',
                staffName: this.staffName || 'ADMIN'
            }).then(res => {
                this.eventLength = res.data.length
            }).catch(err => {
                console.log(err)
            })
        },
        handleCurrentChange(page) {
            this.page = page;
            this.queryPageByCondition();
        },
        handleSizeChange(size) {
            this.size = size;
            this.queryPageByCondition();
        },
        handleClick(row) {
            this.$router.push({ path: `/operatorTaskProcessing?workType=${row.workType}&workStatus=PENDING_PROCESS` });
        }
    }
};
</script>
<style lang="scss" scoped>
.paginationModule {
    text-align: right;
    margin-top: 5px
}

.errText {
    margin-bottom: 10px;

    .eventLength {
        color: rgb(0, 140, 255);
    }
}
</style>